﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;
using KPIS.GERP.GFMS.APP.App_UI.Commons;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.MODEL;

namespace KPIS.GERP.GFMS.APP.App_UI.UserControls
{
    public partial class DropDownList_BgmProjectExpense : System.Web.UI.UserControl
    {
        public RadComboBox Child;
        int nOffset = 10;
        Main main = new Main();
        IBLL_BGM_ProjectOperation pj = new B_BGM_ProjectOperation();
        IBLL_BGM_ProjectOperationExpense pjexp = new B_BGM_ProjectOperationExpense();

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        public RadComboBox GetComboBox()
        {
            RadComboBox ddl = ddlBgmProjectExpSeq;
            return ddl;
        }

        private void LoadData(RadComboBoxItemsRequestedEventArgs e)
        {
            string strFilter = e.Text;
            string strBgmProjectSeq = lblBgmProjectSeq.Text;
            string strBgmSourceSeq = lblBgmSourceSeq.Text;
            //string strBgmYear = lblBgmYear.Text;
            //string strPersonEmpSeq = lblPersonEmpSeq.Text;

            IList<M_BGM_ProjectOperationExpense> infolist = pjexp.GetList(strBgmProjectSeq, strBgmSourceSeq, null);
            
            int itemOffset = e.NumberOfItems;
            int endOffset = Math.Min(itemOffset + nOffset, infolist.Count);
            e.EndOfItems = endOffset == infolist.Count;

            //ddlContactSeq.Items.Clear();

            for (int i = itemOffset; i < endOffset; i++)
            {
                ddlBgmProjectExpSeq.Items.Add(new RadComboBoxItem(infolist[i].m_bgm_projectexpense.m_bgm_mas_expense.bgm_exp_name
                    , infolist[i].bgm_proj_oper_exp_seq.ToString()));
            }

            e.Message = main.GetStatusMessage(endOffset, infolist.Count);
        }

        public void LoadControl(string strBgmProjectSeq, string strBgmSourceSeq
            , Nullable<int> nWidth, Nullable<int> nSetOffset)
        {
            if (nWidth != null)
                ddlBgmProjectExpSeq.Width = Unit.Pixel(nWidth.Value);

            if (nSetOffset != null)
                nOffset = nSetOffset.Value;

            lblBgmProjectSeq.Text = strBgmProjectSeq;
            lblBgmSourceSeq.Text = strBgmSourceSeq;
        }

        public void SetSelectedValue(string strValue)
        {
            if (strValue == null)
            {
                strValue = "";
            }

            if (strValue.Length > 0)
            {
                lblBgmProjectExpSeq.Text = strValue;

                if (ddlBgmProjectExpSeq.FindItemByValue(strValue) == null)
                {
                    M_BGM_ProjectOperationExpense info = pjexp.GetInfo(strValue);
                    ddlBgmProjectExpSeq.SelectedValue = strValue;
                    ddlBgmProjectExpSeq.Text = info.m_bgm_projectexpense.m_bgm_mas_expense.bgm_exp_name;
                }
                else
                {
                    ddlBgmProjectExpSeq.SelectedValue = strValue;
                }
            }
            else
            {
                ddlBgmProjectExpSeq.SelectedIndex = -1;
                ddlBgmProjectExpSeq.Text = "";
            }

            //ddlBgmProjectExpSeq_SelectedIndexChanged(null, null);
        }

        public string GetSelectedValue()
        {
            string strValue = ddlBgmProjectExpSeq.SelectedValue;

            return strValue;
        }

        //protected void ddlBgmProjectExpSeq_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        //{
        //    lblBgmProjectSeq.Text = ddlBgmProjectSeq.SelectedValue;

        //    switch (Page.ToString())
        //    {
        //        case "ASP.app_ui_forms_ess_moneyrequests_aspx":
        //            Forms.ESS_MoneyRequests MoneyReq = (Forms.ESS_MoneyRequests)Page;
        //            MoneyReq.LoadGrdFimMoneyReqDtls();
        //            break;
        //    }
        //}

        protected void ddlBgmProjectExpSeq_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadData(e);
        }
    }
}